package com.xunwulian.base.entity;

import com.xunwulian.base.util.DateStyle;
import com.xunwulian.base.util.DateUtil;

import java.util.Date;

/**
 * Created by liyankai on 2017/3/16.
 */
public class CardNodeEntity extends Entity implements Comparable<CardNodeEntity> {

    // 号段ID = start_end_userOpenDate
    private String cardNodeId;

    // 平台ID
    private String appId;

    // 平台名称
    private String appName;

    /**
     * 用户Id
     */
    private String userId;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 子用户
     */
    private String subUserId;

    /**
     * 子用户名
     */
    private String subUserName;

    // 号段起始
    private long start;

    // 号段结束
    private long end;

    // 有效卡数目
    private Long activeNum;

    // 套餐类型，来自移动
    private Integer pkg;

    // 套餐类型，对用户
    private Integer userPkg;

    // 用户价格
    private Double userPrice;

    // 移动激活日期
    private Date openDate;

    // 客户激活日期，一定是一号
    private Date userOpenDate;

    public CardNodeEntity() {
    }

    public CardNodeEntity(String appId,
                          String appName,
                          String userId,
                          String userName,
                          String subUserId,
                          String subUserName,
                          long start,
                          long end,
                          long activeNum,
                          Integer pkg,
                          Integer userPkg,
                          Double userPrice,
                          Date openDate,
                          Date userOpenDate) {

        this.appId = appId;
        this.appName = appName;
        this.userId = userId;
        this.userName = userName;
        this.subUserId = subUserId;
        this.subUserName = subUserName;
        this.start = start;
        this.end = end;
        this.pkg = pkg;
        this.userPkg = userPkg;
        this.userPrice = userPrice;
        this.openDate = openDate;
        this.userOpenDate = userOpenDate;
        this.activeNum = activeNum;

        // ID
        this.cardNodeId = geneId();
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getSubUserId() {
        return subUserId;
    }

    public void setSubUserId(String subUserId) {
        this.subUserId = subUserId;
    }

    public String getSubUserName() {
        return subUserName;
    }

    public void setSubUserName(String subUserName) {
        this.subUserName = subUserName;
    }


    public long getStart() {
        return start;
    }

    public void setStart(long start) {
        this.start = start;
    }

    public long getEnd() {
        return end;
    }

    public void setEnd(long end) {
        this.end = end;
    }

    public Integer getPkg() {
        return pkg;
    }

    public void setPkg(Integer pkg) {
        this.pkg = pkg;
    }

    public Integer getUserPkg() {
        return userPkg;
    }

    public void setUserPkg(Integer userPkg) {
        this.userPkg = userPkg;
    }

    public Date getOpenDate() {
        return openDate;
    }

    public void setOpenDate(Date openDate) {
        this.openDate = openDate;
    }

    public Date getUserOpenDate() {
        return userOpenDate;
    }

    public void setUserOpenDate(Date userOpenDate) {
        this.userOpenDate = userOpenDate;
    }

    public Double getUserPrice() {
        return userPrice;
    }

    public void setUserPrice(Double userPrice) {
        this.userPrice = userPrice;
    }

    public Long getActiveNum() {
        return activeNum;
    }

    public void setActiveNum(Long activeNum) {
        this.activeNum = activeNum;
    }

    public String getCardNodeId() {
        return cardNodeId;
    }

    public void setCardNodeId(String cardNodeId) {
        this.cardNodeId = cardNodeId;
    }

    public String geneId() {
        return start + "_" + end + "_" + DateUtil.DateToString(userOpenDate, DateStyle.YYYY_MM_DD);
    }

    @Override
    public int compareTo(CardNodeEntity o) {
        if (Long.valueOf(this.start) == Long.valueOf(o.getStart()) &&
                Long.valueOf(this.end) == Long.valueOf(o.getEnd())) {
            return 0;

        } else if (Long.valueOf(this.start) > Long.valueOf(o.getStart()) &&
                Long.valueOf(this.end) > Long.valueOf(o.getEnd())) {
            return -1;
        } else if (Long.valueOf(this.start) < Long.valueOf(o.getStart()) &&
                Long.valueOf(this.end) < Long.valueOf(o.getEnd())) {
            return 1;
        } else {
            throw new AssertionError("node cross!");
        }
    }
}
